<?php

namespace models\admin;

class login extends \models\_SkyCMSModel
{
    
    /**
     * @route=(/login)
     */
    public function index()
    {
        $this->view->render(__METHOD__, null,'admin/adminfooter.php');
    }
    
    /**
     * @route=(/login/result)
     */
    public function result()
    {
        $haslo = md5('##'.$_POST['haslo'].'##');
        
        $query = 'SELECT * FROM users WHERE login="'.$_POST['uzytkownik'].'" AND haslo="'.$haslo.'"';

        $result = $this->db->query($query);
        
        if($result->num_rows > 0) 
        {
            $_SESSION['loggedIn'] = true;
            $_SESSION['login'] = $_POST['uzytkownik'];
            header("Location: ".URL.'_SkyCMS/');
        }
        else
            echo 'Nie można się zalogować :(';
        
    }
    
    /**
     * @route=(/out)
     */
    public function out()
    {
        session_destroy();
        header("Location: ".URL. '_SkyCMS');
    }
}
